package aupdg.data.model.impl;

import aupdg.data.model.Edge;
import aupdg.data.model.Node;

/**
 * Implements the interface Edge. It's an abstract class that implements the
 * common methods of all kind of edges.
 *
 * @author AA and CJ
 */
public abstract class AuGenericEdge implements Edge {

    /**
     * Source node of the edge.
     */
    protected Node source;
    /**
     * Target node of the edge.
     */
    protected Node target;
    /**
     * Edge's label.
     */
    protected String label;

    /**
     * Default constructor.
     */
    public AuGenericEdge() {
    }

    /**
     * Constructor. Creates an edge given a source and target node. It assigns
     * the label.
     *
     * @param source
     * @param target
     * @param label
     */
    public AuGenericEdge(Node source, Node target, String label) {
        this.source = source;
        this.target = target;
        this.label = label;
    }

    @Override
    public Node getSource() {
        return source;
    }

    @Override
    public Node getTarget() {
        return target;
    }

    @Override
    public String getLabel() {
        return this.label;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof AuGenericEdge) {
            AuGenericEdge edge = (AuGenericEdge) obj;
            if (this.source == edge.source && this.target == edge.target) {
                return true;
            }
        }
        return false;
    }
}
